/*************************************************************************
	> File Name: list_dir.c
	> Author: KyleShaw
	> Mail: xtk621@gmail.com 
	> Created Time: 2014-11-27 21:30:34
 ************************************************************************/

#include <stdio.h>
#include <apue.h>
#include <dirent.h>

int main(int argc, char **argv)
{
	DIR *dp;
	struct dirent *dirp;

	if (argc != 2)
		err_quit("usage : ls director_name");

	if ((dp = opendir(argv[1])) == NULL) {
		err_quit("Cannot open %s", argv[1]);
	} else {
		while((dirp = readdir(dp)) != NULL) {
			printf("%s\n", dirp->d_name);
		}
	}
	closedir(dp);
	exit(0);
}
